package com.ruoyi.admin.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.admin.vo.MaintainVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.admin.domain.Maintain;
import com.ruoyi.admin.service.IMaintainService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 维修记录Controller
 *
 * @author ruoyi
 * @date 2022-10-23
 */
@RestController
@RequestMapping("/maintain")
public class MaintainController extends BaseController
{
    @Autowired
    private IMaintainService maintainService;

    /**
     * 查询维修记录列表
     */
    @RequiresPermissions("admin:maintain:list")
    @GetMapping("/list")
    public TableDataInfo list(Maintain maintain)
    {
        startPage();
        List<MaintainVo> list = maintainService.selectMaintainList2();
        return getDataTable(list);
    }

    /**
     * 导出维修记录列表
     */
    @RequiresPermissions("admin:maintain:export")
    @Log(title = "维修记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Maintain maintain)
    {
        List<Maintain> list = maintainService.selectMaintainList(maintain);
        ExcelUtil<Maintain> util = new ExcelUtil<Maintain>(Maintain.class);
        util.exportExcel(response, list, "维修记录数据");
    }

    /**
     * 获取维修记录详细信息
     */
    @RequiresPermissions("admin:maintain:query")
    @GetMapping(value = "/{maintainId}")
    public AjaxResult getInfo(@PathVariable("maintainId") Long maintainId)
    {
        return AjaxResult.success(maintainService.selectMaintainByMaintainId(maintainId));
    }

    /**
     * 新增维修记录
     */
    @RequiresPermissions("admin:maintain:add")
    @Log(title = "维修记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Maintain maintain)
    {
        return toAjax(maintainService.insertMaintain(maintain));
    }

    /**
     * 修改维修记录
     */
    @RequiresPermissions("admin:maintain:edit")
    @Log(title = "维修记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Maintain maintain)
    {
        return toAjax(maintainService.updateMaintain(maintain));
    }

    /**
     * 删除维修记录
     */
    @RequiresPermissions("admin:maintain:remove")
    @Log(title = "维修记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{maintainIds}")
    public AjaxResult remove(@PathVariable Long[] maintainIds)
    {
        return toAjax(maintainService.deleteMaintainByMaintainIds(maintainIds));
    }
}
